/*
包含n个用于间接更新状态的方法的对象模块
 */
import {ADD_TODO, DELETE_TODO, SELECT_ALL_TODOS, DELETE_COMPLETE_TODOS, INIT_TODOS} from './mutation-types'
import storageUtils from '../utils/storageUtils'

export default {

  addTodo ({commit}, todo) {
    // 提交一个comutation请求
    commit(ADD_TODO, {todo}) // 传递给mutation的是一个包含数据的对象
  },

  deleteTodo ({commit}, index) {
    commit(DELETE_TODO, {index})
  },

  selectAll ({commit}, isCheck) {
    commit(SELECT_ALL_TODOS, {isCheck})
  },

  deleteCompleteTodos ({commit}) {
    commit(DELETE_COMPLETE_TODOS)
  },

  init_todos ({commit}) {
    setTimeout(() =>{
      const todos = storageUtils.readTodos()
      console.log(todos)
      commit(INIT_TODOS, todos)// 不一定要传递{}对象，也可以是值todos
    }, 1000)

  }
}
